package cn.edu.nju.software.cdiy.algorithm.performance;
import cn.edu.nju.software.cdiy.bean.*;
import cn.edu.nju.software.cdiy.util.Constant;

public class NetworkAdapterEvaluator implements Evaluator<NetworkAdapter>{

	@Override
	public double getPerformance(NetworkAdapter t) {
		double score = 0;
		
		//总线类型得分
		int busType = t.getBusType().getId();
		double busTypeScore = getBusTypeBase(busType)*Constant.NET_STD_BUSTYPE;
		
		//接口类型得分
		int portType = t.getPortType().getId();
		double portTypeScore = 0;
		if(portType==49) portTypeScore=90;
		else portTypeScore=80;
		portTypeScore = portTypeScore*Constant.NET_STD_PORTTYPE;
		
		//传输速率
		int transmitSpeed = t.getTransmitSpeed().getKey();
		double transmitSpeedScore = getTransmitSpeedBase(transmitSpeed)*Constant.NET_STD_TRANSMITSPEED;
		
		//全双工
		int fullDuplex = t.getFullDuplex();
		double fullDuplexBase = 0;
		if(fullDuplex==1) fullDuplexBase=90;
		else fullDuplexBase=60;
		double fullDuplexScore = fullDuplexBase*Constant.NET_STD_FULLDUPLEX;
		
		//远程唤醒
		int remoteWakeup = t.getRemoteWakeup();
		double remoteWakeupBase = 0;
		if(remoteWakeup==1) remoteWakeupBase=90;
		else remoteWakeupBase=60;
		double remoteWakeupScore = remoteWakeupBase*Constant.NET_STD_REMOTEWAKEUP;
		
		
		
		score = busTypeScore+portTypeScore+transmitSpeedScore+fullDuplexScore+remoteWakeupScore;
		return score;
	}

	private double getTransmitSpeedBase(int transmitSpeed) {
		/*
		 * 传输速率基础分
		 * 556			70
		 * 557			75
		 * 558			80
		 * 559			85
		 * */
		if(transmitSpeed==556)
			return 70;
		else if(transmitSpeed==557)
			return 75;
		else if(transmitSpeed==558)
			return 80;
		else if(transmitSpeed==559)
			return 85;
		else return 80;
	}

	private double getBusTypeBase(int busType) {
		/*
		 * 总线类型基础分
		 * 42			40
		 * 43			80
		 * 44			85
		 * 45			90
		 * 46			60
		 * 47			60
		 * */
		if(busType==42)
			return 40;
		else if(busType==43)
			return 85;
		else if(busType==44)
			return 85;
		else if(busType==45)
			return 95;
		else if(busType==46)
			return 60;
		else if(busType==47)
			return 60;
		else return 60;
	}

}
